<extend name="Public/base"/>

<block name="body">
    <link rel="stylesheet" href="__PUBLIC__/Admin/css/mymember.css">
    <div class="main-title">
        <h2><present name="data"></present>订单列表</h2>
    </div>
    <div class="cf">
      <p style="float:left;">
          <a href="{:U('Order/orderlist',array('sort'=>'asc'))}" class="btn">ID正向排序</a>
          <a href="{:U('Order/orderlist',array('sort'=>'desc'))}" class="btn">ID逆向排序</a>
      </p>
      <!-- 高级搜索 -->
      <div class="search-form fr cf">
        <div class="sleft">
          <input type="text" name="order_num" class="search-input" value="{:I('order_num')}" placeholder="请输入订单号或者会员ID">
          <a class="sch-btn" href="javascript:;" id="search" url="{:U('orderlist')}"><i class="btn-search"></i></a>
        </div>
      </div>
    </div>

    <div class="data-table table-striped">
      <table>
          <thead>
              <tr>
                  <th class="row-selected">
                      <input class="checkbox check-all" type="checkbox">
                  </th>
                  <th>ID</th>
                  <th>会员ID</th>
                  <th>订单号</th>
                  <th>收货人</th>
                  <th>总金额</th>
                  <th>地址ID</th>
                  <th>订单状态</th>
                  <th>购物时间</th>
                  <th>操作</th>
              </tr>
          </thead>
          <tbody>
  				<notempty name="list">
              <volist name="list" id="val">
                  <tr>
                      <td><input class="ids row-selected" type="checkbox" name="id[]" value="{$val.id}"></td>
                      <td>{$val.id}</td>
                      <td><a href="{:U('MyMember/userlist?user_id='.$val['user_id'])}">{$val.user_id}</a></td>
                      <td>{$val.order_num}</td>
                      <td>{$val.receiver}</td>
                      <td>{$val.total}</td>
                      <td><a href="{:U('MyMemberAddr/addrlist?addr_id_id='.$val['addr_id'])}">{$val.addr_id}</a></td>
                      <td>
                          <a class='status' sign="{$val.order_status}" index="{$val.user_id}" href="">{$val.order_status}</a>
                      </td>
                      <td>{$val.shop_time}</td>
                      <td>
                        <a href="{:U('Order/orderDetail?id='.$val['id'])}">订单详情</a>
                        <if condition="$val['order_status'] eq '申请退货' or $val['order_status'] eq '拒绝退货'">
                        <a href="{:U('Order/dealwith?order_num='.$val['order_num'])}">退货处理</a>
                        </if>
                        <if condition="$val['order_status'] eq '已付款'">
                        <a href="{:U('Order/delivery?id='.$val['id'])}">发货</a>
                        </if>
                      </td>
                  </tr>
              </volist>
				<else/>
				<td colspan="10" class="text-center"> aOh! 暂时还没有内容! </td>
				</notempty>
                </tbody>
            </table>
        <div class="page">
            {$_page}
        </div>
    </div>
</block>

<block name="script">
  <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">

        $(function() {
            //搜索功能
            $("#search").click(function() {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function(e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //导航高亮
            highlight_subnav('{:U('orderlist')}');
            //点击排序
        	$('.list_sort').click(function(){
        		var url = $(this).attr('url');
        		var ids = $('.ids:checked');
        		var param = '';
        		if(ids.length > 0){
        			var str = new Array();
        			ids.each(function(){
        				str.push($(this).val());
        			});
        			param = str.join(',');
        		}

        		if(url != undefined && url != ''){
        			window.location.href = url + '/ids/' + param;
        		}
        	});
        });

        //状态操作
        $(function(){
          //获取目标当前的状态，同时进行遍历
          var mystatus = $('.status');
          var num = mystatus.length;
          for (var i=0;i<num;i++) {
            // 对当前的状态获取之后，设置当前状态的操作
            if(mystatus.eq(i).attr('sign')=='启用'){
                mystatus.eq(i).html('禁用');
            }
            if(mystatus.eq(i).attr('sign')=='禁用'){
                mystatus.eq(i).html('启用');
            }
          }
        });

        // 绑定每个按钮的点击事件
        $('.status').each(function(){
          $(this).click(function(){
              // 获取当前目标所绑定的的索引，即本行的user_id
              var user_id = $(this).attr('index');
              // 运用ajax中的post方法传递参数，获取本行的user_id
              $.get("{:U('MyMember/change')}" , {user_id:user_id} , function(){

              } );
              // 点击修改目标的属性，同属修改HTML标签里面的显示内容
              var mystatus=$(this).parent().prev();
              var status=$(this).attr('sign');
              if(status=='启用'){
                  $(this).html('启用');
                  $(this).attr('sign','禁用');
                  mystatus.html('禁用');
              }
              if(status=='禁用'){
                  $(this).html('禁用');
                  $(this).attr('sign','启用');
                  mystatus.html('启用');
              }
              // 取消里面的默认行为
              return false;
          });
        });
    </script>
</block>
